#ifdef __cplusplus
extern "C" {
#endif

__INLINE__ void Sim_CleanupStack () {
    __ASM__ __VOLATILE__ ("add $0x4,%esp\n"); // pop arg0 (context) pushed by CPUState::setupStack
    __ASM__ __VOLATILE__ ("pop %ebp\n");      // restore EBP pushed by CPUState::setupStack
}

__INLINE__ void Sim_nop () {
    __ASM__ __VOLATILE__ ("nop\n");
}

__INLINE__ uint64 Sim_GetClock () {
    uint32 lo;
    uint32 hi;
    __ASM__ __VOLATILE__ ("rdtsc" : "=a" (lo), "=d" (hi));
    return ((uint64)hi << 32) | ((uint64)lo);
}

#ifdef __cplusplus
};
#endif
